<template>
  <el-container>
    <el-header>
      <div class="logoleft">
        <!-- <span class="texts">
          <img src="../../assets/images/sdtlogo.png" style="width: 30px; height: 30px" />
        </span> -->
        <span style="font-size: 18px;" @click="timeoutsExit"> {{ systemName }}</span>
      </div>
      <div class="titlesright">
        <span style="font-size: 14px; margin-top: 5px">欢迎您 {{ userName }}</span>
        <span v-show="absoarrowled">
          <i class="el-icon-s-home" @click="barnck"></i>
        </span>
        <span class="baioqspan">
          <el-popover placement="top" width="160" v-model="visible">
            <div>
              <li class="el-menu-item" @click="denglus">退出登录</li>
              <!--<li class="el-menu-item" @click="xiugas">修改密码</li>-->
              <li class="el-menu-item" @click="guayus">关于</li>
              <!--<li class="el-menu-item">升级</li>-->
              <li class="el-menu-item" @click="uninstall">卸载</li>
            </div>
            <i slot="reference" class="el-icon-s-unfold"></i>
          </el-popover>
        </span>
        <span class="el-icon-minus" @click="minimizeWin"></span>
        <!-- <span class="el-icon-full-screen" @click="maximizeWin"></span> -->
        <!-- <span class="el-icon-close" @click="closeWin" v-show="patters === 'development'"></span> -->
      </div>
      <div class="comrooms">
        <span v-show="absoarrowled">{{ comtecont }}</span>
      </div>
    </el-header>
    <el-main style="padding: 0 !important">
      <router-view></router-view>
    </el-main>
    <el-dialog title="修改密码" :visible.sync="diadldxiugais" width="46%" :before-close="handleClxiu">
      <div class="dengshus">
        <el-form :inline="true" :model="fordmxiu" class="demo-form-inline" label-width="110px">
          <!-- <el-row>
            <el-col :span="6"> -->
          <el-form-item label="原密码">
            <el-input v-model="fordmxiu.uyser" placeholder="请输入原密码"></el-input>
          </el-form-item>
          <!-- </el-col>
          </el-row> -->
          <el-form-item label="新密码">
            <el-input v-model="fordmxiu.uxser" placeholder="请输入新密码"></el-input>
          </el-form-item>
          <el-form-item label="确认新密码">
            <el-input v-model="fordmxiu.uzxser" placeholder="请再输入新密码"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="diadldxiugais = false">取 消</el-button>
        <el-button type="primary" @click="diadldxiugais = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="关于" :visible.sync="dialogVisible" width="46%" :before-close="handleClose">
      <div style="font-size: 16px; margin: 16px">
        <div class="dandus" style="margin: 18px">
          <span>
            <img style="width:150px" height="40px" src="../../assets/images/sdtlogo.png" />
          </span>
          <span>
            <p style="margin: 10px">
              兴唐通信科技有限公司（数据通信科学技术研究所）
            </p>
            <!-- <p></p> -->
          </span>
        </div>
        <div>版本：{{ versionNumber }}({{ temModename }})</div>
        <li>版权：Copyright@{{ copyright }}</li>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="AQBMTJ" :visible.sync="disabusqxieass" width="46%" :before-close="handxiesClose">
      <div>
        <el-form :inline="true" class="demo-form-inline" label-width="110px">
          <el-form-item label="卸载号：">
            <span>2890032</span>
          </el-form-item>
          <!--<el-form-item label="请输入卸载码：">-->
          <!--<el-input v-model="xieahsa" placeholder="请再输入新密码"></el-input>-->
          <!--</el-form-item>-->
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="disabusqxieass = false">取 消</el-button>
        <el-button type="primary" @click="clirzies">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="dialogConemit" width="60%" @close="dialogConemit = false" :close-on-click-modal="false"
      :close-on-press-escape="false" custom-class="strategy-dialog equip-detail el-dialog-widthSmall" v-dialogDrag
      @closed="dialogcdClosed">
      <el-form ref="infoemdForm" :model="infoemdForm" label-width="90px">
        <el-row style="width: 66%; margin: 0 auto">
          <el-tabs v-model="activeName" type="card">
            <el-tab-pane label="U盘登录" name="first">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="责任人">
                    <el-input v-model.trim="infoemdForm.userName" placeholder="请输入责任人" clearable
                      disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="密级">
                    <el-input v-model.trim="infoemdForm.level" placeholder="请输入密级" clearable disabled="true"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="密码">
                    <el-input v-model.trim="infoemdForm.passwd" placeholder="请输入密码" clearable show-password></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row style="text-align: center">
                <el-checkbox v-model="checkuped">格式化U盘</el-checkbox>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="修改" name="second">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="原始密码">
                    <el-input v-model.trim="infoemdForm.oldpass" placeholder="请输入原始密码" clearable
                      show-password></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="新密码">
                    <el-input v-model.trim="infoemdForm.newpass" placeholder="请输入新密码" clearable
                      show-password></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="确认密码">
                    <el-input v-model.trim="infoemdForm.newpass1" placeholder="请输入确认密码" clearable
                      show-password></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <p>密码长度为8~16位，且必须为数字、大小写字母或符号至少2种</p>
            </el-tab-pane>
          </el-tabs>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogConemit = false">取 消</el-button>
        <el-button type="primary" v-show="activeName == 'first'" @click="confirmInfo">登 录</el-button>
        <el-button type="primary" v-show="activeName == 'second'" @click="modifclis">确 定</el-button>
      </span>
    </el-dialog>
  </el-container>
</template>
<script>
// import { ipcRenderer } from "electron";
//返回主页面
window.electron.ipcRenderer.on("b", (e, data) => {
  console.log(e, data);
  if (data == "bark") {
    vm.getList();
  }
});
// 环境判断
// window.electron.ipcRenderer.on("pattern", (e, data) => {
//   console.log(e, data);
//   vm._data.patters = data;
//   console.log(vm._data.patters);
// });
// // 登录认证
// window.electron.ipcRenderer.on("auth", (e, data) => {
//   if (data == "cation") {
//     vm.loglist();
//   }
// });
// // 注销认证
// window.electron.ipcRenderer.on("cancel", (e, data) => {
//   if (data == "lation") {
//     vm.calation();
//   }
// });
var vm = null; //介质
export default {
  name: "AQBMTJ",
  data() {
    return {
      copyright: window.copyright,
      versionNumber: '',
      activeIndex: "1",
      userName: window.sessionStorage.getItem("userName"),
      visible: false,
      diadldxiugais: false,
      fordmxiu: {
        uyser: "",
        uxser: "",
        uzxser: "",
      },
      xieahsa: "",
      dialogVisible: false,
      absoarrowled: false,
      disabusqxieass: false,
      systemName: window.systemName,
      comtecont: "",
      metitList: [
        {
          indexPath: "/identifications",
          menuName: "身份鉴别",
        },
        {
          indexPath: "/clientAudits",
          menuName: "审计日志",
        },
        {
          indexPath: "/accessControls",
          menuName: "策略管理",
        },
        {
          indexPath: "/systemSetting",
          menuName: "系统设置",
        },
        {
          indexPath: "/assetManagement",
          menuName: "资产管理",
        },
        {
          indexPath: "/install",
          menuName: "配置向导",
        },
      ],
      patters: "",
      timer: null,
      timers: null,
      timerss: null,
      temModename: window.systemMode == "SINGLE" ? "单机版" : "网络版",
      loginMode: window.loginMode,
      infoForm: {
        pcName: "",
        AssetNo: "",
        os: "",
        cpuModel: "",
        mac: "",
        ip: "",
        UnitName: "23",
        DeptName: "",
        DeptID: "",
        UnitID: "",
        EmpName: "",
        EmpID: "1",
        SecLvl: "1",
        Machine: "",
        HostType: "1", //0-网络版在线注册 1-单机版 2-网络版离线注册
        accountList: "",
      },
      sjitrmes: "",
      dialogConemit: false,
      infoemdForm: {
        userName: "",
        level: "",
        passwd: "",
        oldpass: "",
        newpass: "",
        newpass1: "",
      },
      activeName: "",
      checkuped: true,
      diskmsobj: {},
      timerExits: window.timerExits,
    };
  },
  created: function () {
    //=====关键
    vm = this; //=====关键
    this.getForm();
    this.gitvuse()
  },
  watch: {
    $route(to, from) {
      // console.log(from.path); //从哪来
      // console.log(to.path, "1111"); //到哪去]
      // console.log(this.$route.path);
      if (this.$route.path == "/home") {
        this.absoarrowled = false;
      } else {
        console.log(this.metitList);
        this.metitList.forEach((res) => {
          if (res.indexPath == to.path) {
            this.comtecont = res.menuName;
            console.log(this.comtecont);
          }
        });
        console.log(this.comtecont);
        this.absoarrowled = true;
      }
    },
  },
  mounted() {
    this.timer = setInterval(() => {
      // if (this.patters != "development") {
      //   this.receivlist();
      // }
      this.receivlist();
    }, 5000);
    this.timers = setInterval(() => {
      this.disklisc();
    }, 1000);
  },
  beforeDestroy() {
    this.$once("hook:beforeDestroy", () => {
      clearInterval(this.timer);
      clearInterval(this.timers);
      clearInterval(this.timerss);
    });
  },
  methods: {
    // 超时退出
    timeoutsExit() {
      if (this.timerss) {
        clearInterval(this.timerss)
        this.timerss = setInterval(() => {
          this.denglus();
        }, this.timerExits);
      } else {
        this.timerss = setInterval(() => {
          this.denglus();
        }, this.timerExits);
      }
    },
    // 发送
    minimizeWin() {
      window.electron.ipcRenderer.send("window-min");
    },
    maximizeWin() {
      window.electron.ipcRenderer.send("window-max");
    },
    closeWin() {
      window.electron.ipcRenderer.send("window-close");
    },
    // 退出登录
    denglus() {
      let adminObj = JSON.parse(
        window.localStorage.getItem("administratorLog")
      );
      console.log(adminObj);
      if (adminObj) {
        adminObj.push({
          LoginUser: window.sessionStorage.getItem("userName"),
          EmpName: this.infoForm.EmpName,
          DeptName: this.infoForm.DeptName,
          IP: this.infoForm.ip,
          OpTime: this.sjitrmes,
          Content: "退出",
        });
        window.localStorage.setItem(
          "administratorLog",
          JSON.stringify(adminObj)
        );
      } else {
        let adminObj = [];
        adminObj.push({
          LoginUser: window.sessionStorage.getItem("userName"),
          EmpName: this.infoForm.EmpName,
          DeptName: this.infoForm.DeptName,
          IP: this.infoForm.ip,
          OpTime: this.sjitrmes,
          Content: "退出",
        });
        window.localStorage.setItem(
          "administratorLog",
          JSON.stringify(adminObj)
        );
      }
      this.visible = false;
      this.$router.push("/login");
      // window.electron.ipcRenderer.send("windowLogin");
    },
    getForm() {
      this.$get("/vgmp/config/gethostinfo").then((res) => {
        let { data } = res.data;
        this.infoForm = {
          DeptID: data.deptId,
          DeptName: data.deptName,
          UnitID: data.unitId,
          EmpName: data.empName,
          SecLvl: data.secLevel,
          Machine: data.machine,
          AssetNo: data.assetNum,
          AddressInfo: data.addressInfo,
          HostType: data.hostType, //0-网络版在线注册 1-单机版 2-网络版离线注册
          EmpID: data.empId,
          UnitName: data.unitName,
          licenseModel: data.licenseModel,
          os: data.os,
          pcName: data.pcName,
          cpuModel: data.cpuModel,
          ip: data.ip,
          mac: data.mac,
        };
        let val = "";
        data.accountList.forEach((item) => {
          val += item.accountInfo.account + ",";
        });
        this.infoForm.accountList = val.slice(0, val.lastIndexOf(","));
      });
      var myDate = new Date();
      let nian = myDate.getFullYear();
      let yuef = "";
      let rizi = "";
      let shi = myDate.getHours();
      let fen = myDate.getMinutes();
      let maio = myDate.getSeconds();
      if (myDate.getMonth() + 1 >= 10) {
        yuef = myDate.getMonth() + 1;
      } else {
        yuef = "0" + (myDate.getMonth() + 1);
      }
      if (myDate.getDate() >= 10) {
        rizi = myDate.getDate();
      } else {
        rizi = "0" + myDate.getDate();
      }
      this.sjitrmes =
        nian +
        "-" +
        yuef +
        "-" +
        rizi +
        " " +
        (shi < 10 ? "0" + shi : shi) +
        ":" +
        (fen < 10 ? "0" + fen : fen) +
        ":" +
        (maio < 10 ? "0" + maio : maio);
    },
    gitvuse() {
      this.$get("/api/v1/getversion").then(res => {
        console.log(res.data)
        this.versionNumber = res.data.version
      })
    },
    // 修改密码
    xiugas() {
      this.visible = false;
      this.diadldxiugais = true;
    },
    // 关于
    guayus() {
      this.visible = false;
      this.dialogVisible = true;
    },
    // 卸载
    uninstall() {
      this.visible = false;
      this.disabusqxieass = true;
    },
    barnck() {
      this.$router.push("/home");
    },
    getList: function () {
      this.$router.push("/home");
    },
    handleClxiu() {
      this.diadldxiugais = false;
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handxiesClose() {
      this.dialogVisible = false;
    },
    clirzies() {
      this.$confirm("确认卸载？")
        .then((_) => {
          this.disabusqxieass = false;
          const loading = this.$loading({
            lock: true,
            text: "系统正在卸载中，请耐心等待！",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          this.$delete("/vgmp/config/uninstall").then((res) => {
            console.log(res, "卸载返回数据");
            if (res.data.errorcode == "0") {
              //设置60秒
              setTimeout(() => {
                loading.close();
                //清空localStorage,返回初始化
                window.localStorage.removeItem("administratorLog");
              }, 60000);
            } else {
              loading.close();
              this.$message({
                message: res.data.errormsg,
                type: "error",
              });
            }
          });
        })
        .catch((_) => { });
    },
    //告警日志接口
    receivlist() {
      // this.$notify({
      //   title: "成功",
      //   message: "这是一条成功的提示消息",
      //   type: "",
      //   position: 'bottom-right'
      // });
      // window.electron.ipcRenderer.send("flashisticons"); //图标闪烁
      this.$get("/bdgl/alert/receive").then((res) => {
        if (res.data.errorcode == "0") {
          let types = "";
          res.data.data.forEach((item) => {
            if (item.level == "0") {
            } else if (item.level == "1") {
              types = "warning";
            } else if (item.level == "2") {
              types = "error";
            }
            if (item.title != "") {
              this.$notify({
                title: item.title,
                message: item.msg,
                type: types,
                position: "bottom-right",
              });
            }
          });
        }
      });
    },
    // 红盘信息
    disklisc() {
      this.$get("bdgl/alert/rdiskmsg").then((res) => {
        console.log(res.data.data, "红盘信息————————————————");
        let data = res.data.data[0];
        if (res.data.data.length != 0) {
          if (data.msg_type == "REDDISK_PLUGIN") {
            if (data.content.result == true) {
              this.dialogConemit = true;
              this.activeName = "first";
              this.diskmsobj = res.data.data[0];
              if (this.diskmsobj.content.level == 1) {
                this.infoemdForm.level = "内部";
              } else if (this.diskmsobj.content.level == 2) {
                this.infoemdForm.level = "秘密";
              } else if (this.diskmsobj.content.level == 3) {
                this.infoemdForm.level = "机密";
              } else if (this.diskmsobj.content.level == 4) {
                this.infoemdForm.level = "绝密";
              }
              this.rdiskges();
            } else {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(() => { })
                .catch(() => { });
            }
          } else if (data.msg_type == "REDISK_MOUNT") {
            if (data.content.result == true) {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "success",
              })
                .then(() => { })
                .catch(() => { });
            } else {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(() => { })
                .catch(() => { });
            }
          } else if (data.msg_type == "REDISK_CHANGE_PASSWORD_RSP") {
            if (data.content.result == true) {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "success",
              })
                .then(() => { })
                .catch(() => { });
            } else {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(() => { })
                .catch(() => { });
            }
          } else if (data.msg_type == "REDDISK_LOGIN_RSP") {
            if (data.content.result == true) {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "success",
              })
                .then(() => { })
                .catch(() => { });
            } else {
              this.$confirm(`${data.content.error_msg}`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
              })
                .then(() => { })
                .catch(() => { });
            }
          } else if (data.msg_type == "REDDISK_PLUGOUT") {
            this.$confirm(`红盘登出！`, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => { })
              .catch(() => { });

          }
        }
      });
    },
    rdiskges() {
      let data = {
        content: {},
        msg_type: "GET_UDISKLIST",
      };
      this.$postForJson("/3in1/config/rdiskgetdisklist", data).then((res) => {
        console.log(res.data.data.udisks[0].userName, "2222222222222222222");
        this.infoemdForm.userName = res.data.data.udisks[0].userName;
      });
    },
    dialogcdClosed() {
      this.dialogConemit = false;
      this.infoemdForm.passwd = "";
      this.infoemdForm.newpass = "";
      this.infoemdForm.newpass1 = "";
      this.infoemdForm.oldpass = "";
    },
    confirmInfo() {
      let data = {
        msg_type: "UDISK_LOGIN",
        content: {
          passwd: this.infoemdForm.passwd,
          dev_info: this.diskmsobj.content.dev_info,
          format: this.checkuped == true ? 1 : 0,
        },
      };
      this.$postForJson("3in1/config/rdisknoticelogin", data).then((res) => {
        console.log(res);
        if (res.data.errorcode == 0) {
          this.$message({
            message: "正在登录，请稍后！",
            type: "success",
          });
          this.dialogConemit = false;
        } else {
          this.$message({
            message: res.data.errormsg,
            type: "error",
          });
          this.dialogConemit = false;
        }
      });
    },
    modifclis() {
      if (this.infoemdForm.newpass != this.infoemdForm.newpass1) {
        this.$message({
          message: "密码不一致",
          type: "warning",
        });
        return;
      }
      let data = {
        msg_type: "CHANGE_PASSWD",
        content: {
          new_password: this.infoemdForm.newpass,
          old_password: this.infoemdForm.oldpass,
          dev_info: this.diskmsobj.content.dev_info,
        },
      };
      this.$postForJson("3in1/config/rdisknoticechange", data).then((res) => {
        console.log(res.data.errorcode);
        if (res.data.errorcode == 0) {
          this.$message({
            message: "正在修改，请稍后！",
            type: "success",
          });
          this.dialogConemit = false;
        } else {
          this.$message({
            message: res.data.errormsg,
            type: "error",
          });
          this.dialogConemit = false;
        }
      });
    },
  },
};
</script>
